package com.yycx.module.bus.provider.controller;

import cn.hutool.core.map.MapUtil;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.security.OpenUser;
import com.yycx.common.springmvc.base.BaseController;
import com.yycx.module.bus.client.entity.BusSaleman;
import com.yycx.module.bus.provider.service.BusSalemanService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;


/**
 * 业务员控制器
 *
 * @author flyme
 * @date 2020-07-29
 */
@RestController
@RequestMapping("/bus/saleman/")
public class BusSalemanController extends BaseController<BusSalemanService, BusSaleman> {

    @ApiOperation(value = "业务员-分页列表", notes = "业务员分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "业务员-列表", notes = "业务员列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    @ApiOperation(value = "业务员-添加", notes = "添加业务员")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "业务员-更新", notes = "更新业务员")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "业务员-更新资信信息", notes = "更新资信信息")
    @PostMapping(value = "updateAmount")
    public ResultBody updateAmount(@RequestParam(required = false) Map params) {
        bizService.updateAmount(params);
        return ResultBody.msg("更新成功");
    }


    @ApiOperation(value = "业务员-删除", notes = "删除业务员")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "业务员-详情", notes = "业务员详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }

    @ApiOperation(value = "更新业务员", notes = "更新业务员")
    @PostMapping(value = "setSalemanState")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "ids", required = true, value = "主键", paramType = "form"),
        @ApiImplicitParam(name = "salemanState", required = true, value = "状态值", paramType = "form")
    })
    public ResultBody setSalemanState(@RequestParam(required = false) Map map, @RequestParam(value = "salemanState") Integer salemanState) {
        return bizService.setState(map, "salemanState", salemanState);
    }


    @ApiOperation(value = "同步海鹰数据", notes = "同步海鹰数据")
    @PostMapping(value = "syncHyData")
    public ResultBody syncHyData() {
        OpenUser openUser = OpenHelper.getUser();
        bizService.syncHyData(openUser);
        return ResultBody.msg("同步请求已提交,请稍后刷新查看,请勿重复提交");
    }

    @ApiOperation(value = "同步业务员到海鹰", notes = "同步业务员到海鹰")
    @PostMapping(value = "syncToHy")
    public ResultBody syncToHy(Long saleManId) {
        bizService.syncToHy(saleManId);
        return ResultBody.msg("同步完成");
    }

    /**
     * 导出数据
     *
     * @param params
     * @param request
     * @param response
     */
    @PostMapping(value = "export")
    public void export(@RequestParam(required = false) Map params, HttpServletRequest request, HttpServletResponse response) {
        String handlerName = MapUtil.getStr(params, "handlerName");
        String fileName = MapUtil.getStr(params, "fileName");
        bizService.export(params, request, response, fileName, fileName, handlerName);
    }
}
